<?php
// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "../config/config.php";
include "../auth.php";
include "../DBManager.php";

// -----------------------------------------------------------------------------
// 访问设置
// -----------------------------------------------------------------------------

if (!(isset($_GET["keyword"]) || isset($_GET["searchArea"]))) {
    exit("需要传入有效的参数！");
}

$keyword = $_GET["keyword"];
$searchArea = $_GET["searchArea"];

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

$dbPath = "../" . $dbPath; // 不加这行语句的话会报错，提示找不到对应路径
$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------

echo <<<BBB
<!--list group start-->
<div class="list-group mt-3 mb-3">
BBB;

// -----------------------------------------------------------------------------

$rows = $db->search($keyword, $searchArea);
if ($rows == false) {
    echo <<<BBB
        <div class="mt-0 alert alert-info" role="alert">
            <p class="mb-0">暂时没有相关结果。</p>
        </div>
    BBB;
} else {
    foreach ($rows as $row) {

        extract($row);
        $url = "../category/linksInCategory.php?categoryId={$categoryId}&linkId={$id}";

        echo <<<BBB
            <a href="$url" class="list-group-item list-group-item-action d-flex" target="_self">
               <span class="w-100 text-break">$title</span>
               <span class="flex-shrink-0">
                   <span class="badge rounded-pill text-bg-light">{$timesOfClick}点击</span>
               </span>
            </a>
        BBB;

    }
}

// -----------------------------------------------------------------------------

echo <<<BBB
</div>
<!--list group end-->
BBB;

// -----------------------------------------------------------------------------
